// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App';
import router from './router';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import moment from 'moment';
import axios from 'axios';
import Qs from 'qs';
import 'babel-polyfill';
import './assets/js/component';
// import VueAMap from 'vue-amap';
import echarts from "echarts";
import { debug } from 'util';
require('animate.css');
Vue.prototype.$echarts = echarts;
// Vue.use(VueAMap);
Vue.use(ElementUI);
// VueAMap.initAMapApiLoader({
//   key: '247118c119020046a5d17118291f8654',
//   plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor','AMap.MarkerClusterer'],
//   v: '1.4.4'
// });
Vue.config.productionTip = false;
Vue.prototype.$bus = new Vue();
Vue.prototype.dateMoment = (time, string='YYYY-MM-DD HH:mm:ss') => {
  if (!time) {
    return
  }
  return moment(time).format(string);
};
Vue.prototype.dateTable = (row,column) => {
  if (!row[column.property]) return '';
  return moment(row[column.property]).format('YYYY-MM-DD');
};
Vue.filter('dateformat', function (dataStr, pattern = 'YYYY-MM-DD') {
  if (dataStr) {
    return moment(dataStr).format(pattern)
  } else {
    return dataStr
  }
});
Vue.prototype.isEmpty = (obj) => {
  let status = true;
  for(let k in obj) {
    if (!obj[k]) status = false
  }
  return status;
};
Vue.prototype.filterNoneObj = (obj) => {
  for(let k in obj) {
    if (obj[k]=='' || obj[k]==null || obj[k].length == 0 || obj[k]=='全部') delete(obj[k]);
  }
  return obj;
};

// 创建ajax
// 张红阳本地ip地址
// Vue.prototype.$bus.baseURL = '//192.168.0.155:8080/webAPI/';
// 袁志伟本地ip地址
// Vue.prototype.$bus.baseURL = '//192.168.0.128:8080/webAPI/';
// 刘洋本地ip地址
// Vue.prototype.$bus.baseURL = '//192.168.0.152:8080/webAPI/';
// 鹏飞本地ip
Vue.prototype.$bus.baseURL = '//192.168.0.127:8084/';
Vue.prototype.$uploadfile = Vue.prototype.$bus.baseURL + 'upload/fileUpload'
Vue.prototype.$downfile = Vue.prototype.$bus.baseURL + 'upload/downFile?fileName='
Vue.prototype.axios = axios.create({
  baseURL: Vue.prototype.$bus.baseURL,
  timeout: 10000,
  // withCredentials: true,
  transformRequest: [function (data) {
    data = JSON.stringify(data);
    return data;
  }],
  // 设置Content-Type
  headers: {
    'Content-Type': 'application/json',
    // 'token': gettoken()
  }
});
Vue.prototype.axios.interceptors.request.use(
  config => {
    let token = sessionStorage.getItem('token');
    if(token){
      config.headers.token = token;
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);
Vue.prototype.axios.interceptors.response.use(
  response => {
    if (response.data.code == 401 || response.code == 402) {
      Vue.prototype.$message({
        message: '未登录或登录已过期请重新登录',
        type: 'warning'
      });
      // router.push({
      //   path:"/",
      //   querry:{redirect:router.currentRoute.fullPath}//从哪个页面跳转
      // });
      sessionStorage.clear();
      return
    } else if (response.data.code == 200) {
       return response;
    } else {
      if (response.data.message) {
        Vue.prototype.$message({
          message: response.data.message,
          type: 'warning'
        });
      }
      console.log(response);
      return response;
    }
    
  },
  error => {
    // Vue.prototype.$message({
    //   message: '服务器超时或者请求错误',
    //   type: 'warning'
    // });
    return Promise.reject(error); // 返回接口返回的错误信息
  });
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
});
